#include<bits/stdc++.h>
#define ll long long
#define L x<<1
#define R x<<1|1
#define mid ((l+r)>>1)
#define lc L,l,mid
#define rc R,mid+1,r
#define Root 1,1,n
#define OK Ll<=l&&r<=Rr
#define rep(x,y,z) for(int x=(y);x<=(z);x++)
#define per(x,y,z) for(int x=(y);x>=(z);x--)
#define repn(x) rep(x,1,n)
#define repm(x) rep(x,1,m)
#define pb push_back
#define e(x) for(int i=h[x],y=to[i];i;i=nxt[i],y=to[i])
#define E(x) for(auto y:p[x])
#define Pi pair<int,int>
#define ui unsigned ll
#define YY puts("Yes"),exit(0)
#define NN puts("No"),exit(0)
#define yy return puts("Yes"),void()
#define nn return puts("No"),void()
inline int read(){int s=0,w=1;char c=getchar();while(c<48||c>57) {if(c=='-') w=-1;c=getchar();}while(c>=48&&c<=57)s=(s<<1)+(s<<3)+c-48,c=getchar();return s*w;}
inline void pf(int x){if(x<0) putchar('-'),x=-x;if(x>9)pf(x/10);putchar(x%10+48);}
using namespace std;
const int N=2e5+5,M=1e6+5,inf=(1LL<<30)-1,mod=1e9+7;
const ll llf=1e18;
inline void add(int &a,int b){((a+=b)>=mod) and (a-=mod);}
inline int Add(int a,int b){return add(a,b),a;}
inline int mul(int a,int b){return 1LL*a*b%mod;}
inline void Mul(int &a,int b){a=mul(a,b);}
inline void red(int &a,int b){add(a,mod-b);}
inline int Red(int a,int b){return red(a,b),a;}
inline int qp(int a,ll b){if(!b)return 1;int c=qp(a,b>>1LL);Mul(c,c);if(b&1)Mul(c,a);return c;}
inline int INV(int x){return qp(x,mod-2);}
inline bool che(int x,int p){return (x>>p)&1LL;}
int n,h[N],to[N<<1],nxt[N<<1],cnt,f[N],ans;
inline void add_(int a,int b){
	to[++cnt]=b,nxt[cnt]=h[a],h[a]=cnt;
}
int dep[N],siz[N],son[N],top[N],dfn[N],Time;
vector<int>d[N],p[N];
inline void dfs(int x,int fa){
	dep[x]=dep[fa]+1,dfn[x]=++Time,d[dep[x]].pb(x),siz[x]=1;
	e(x)dfs(y,x),siz[x]+=siz[y],son[x]=siz[y]>siz[son[x]]?y:son[x];
}
inline void Dfs(int x,int low){
	top[x]=low;
	if(son[x])Dfs(son[x],low);
	e(x)if(y^son[x])Dfs(y,y);
}
inline int lca(int x,int y){
	while(top[x]^top[y])dep[top[x]]>dep[top[y]]?x=f[top[x]]:y=f[top[y]];
	return dep[x]<dep[y]?x:y;
}
int dp[N][2],pw[N],s[N],tp;
inline void dfs_(int x){
	dp[x][0]=dp[x][1]=0;
	if(p[x].empty())return dp[x][0]=dp[x][1]=1,void();
	vector<int>q,pr;
	E(x)dfs_(y),q.pb(y),pr.pb(0);
	int sz=q.size();
	int W0=1,S=1;
	rep(i,0,sz-1){
		Mul(S,Add(dp[q[i]][0],dp[q[i]][1]));
		pr[i]=W0;
		Mul(W0,dp[q[i]][0]);
	}
	W0=1;
	per(i,sz-1,0){
		add(dp[x][1],mul(dp[q[i]][1],mul(W0,pr[i])));
		Mul(W0,dp[q[i]][0]);
	}
	dp[x][0]=Red(S,dp[x][1]);
	p[x].clear();
}
inline void Main(){
	n=read(),pw[0]=1;
	rep(i,1,n+1)pw[i]=Add(pw[i-1],pw[i-1]);
	repn(i)add_(f[i]=read(),i);
	dfs(0,0),Dfs(0,0);
	rep(g,1,n+1)if(!d[g].empty()){
		if((int)d[g].size()==1){
			add(ans,pw[n]);
			continue;
		}
		tp=0;
		int sz=d[g].size();
		s[++tp]=d[g][0];
		rep(i,1,sz-1){
			int x=d[g][i],l=lca(x,d[g][i-1]);
			while(tp>1&&dep[l]<dep[s[tp-1]])p[s[tp-1]].pb(s[tp]),tp--;
			if(tp&&dep[l]<dep[s[tp]])p[l].pb(s[tp]),tp--;
			if(!tp||l!=s[tp])s[++tp]=l;
			s[++tp]=x;
		}
		// cerr<<tp<<'\n';
		rep(i,1,tp-1)p[s[i]].pb(s[i+1]);
		int rt=lca(d[g][0],d[g][sz-1]);
		// cerr<<(int)p[rt].size()<<'\n';
		dfs_(rt);
		add(ans,mul(pw[n+1-sz],dp[rt][1]));
	}
	cout <<ans;
}
signed main(){
	freopen("a.in","r",stdin);
	freopen("a.out","w",stdout);
	int T=1;
	while(T--)Main();
	return 0;
}
